import Index from "./index.vue";
import Vue from "vue";

export const imgPreview = (props) => {
  const { urlList } = props;
  const $preview = new (Vue.extend(Index))({
    propsData: {
      urlList,
      onClose: () => {
        document.body.removeChild($preview.$el);
      },
    },
  }).$mount();
  document.body.appendChild($preview.$el);
};

Vue.prototype.$imgPreview = imgPreview;

const Indexer = {
  bind(el, binding, vnode) {
    const { urlList } = (binding.value && binding.value) || [];
    el.addEventListener("click", () => {
      console.log(urlList);
      imgPreview({ urlList });
    });
  },
};

export default Indexer;
